$(function(){
	
	//加载--学员信息
	function requestSuccess(data){
		if( data.status == true ){

				$(".name").html(data.data.content[0].name);
				$(".gender").html(data.data.content[0].gender);
				$(".age").html(data.data.content[0].age);
				$(".birth").html(data.data.content[0].birth);
				$(".phone").html(data.data.content[0].phone);
				$(".linkman").html(data.data.content[0].linkman);
				$('.saler-list option:selected').html(data.data.content[0].follower);
				$('.saler-list option:selected').val(data.data.content[0].counselorId);
				
			}else{
				alert("获取信息失败");
			}
	}

	function requestError(data){
		alert("获取信息失败 error");
	}

	//加载顾问信息
	function requestCounselorsS(data){
		if( data.status == true ){
			$(".saler-list").html("");
			var str = "";
			for( var i = 0; i< data.data.content.length; i++ ){
				var item = data.data.content[i];
				str += '<option  class = ""'+ 'value ="'+item.id+'">'+item.name+'</option>';

			}
			
			$(".saler-list").html(str);
		}
	}
	function requestCounselorsE(data){
		alert("获取顾问失败+error");
	}

	//签订合同
	function signSuccess(data){
		if( data.status == true ){
			alert("签订成功");
			location.href = "contract-mg.html";
		}else{
			alert("签订失败");
		}
	}
	function signError(data){
		alert("签订失败+error");
	}

	//--确认合同
	$(".sign").click(function(){

			var data = {
				"name": $(".name").html(),
				"follower": $('.saler-list option:selected').html(),
				"studentId": localStorage.childId,
				"time": $(".createdTime").html(),
				"points":$(".points").html(),
				"shouldPaid": $(".shouldPay").html(),
				"reallyPaid": $(".pay").html(),
				"description": $(".other").html(),
				"remainingClass": $(".remainingClass").html(),
				"type": $('.type option:selected').val()
			};
			console.log(data);
			
			Ajax({
				url: "http://106.75.143.27/contracts",
				type: "post",
				data: JSON.stringify(data),
				contentType: 'application/json',
				dataType: 'json',
				call1:  signSuccess,
				call2:  signError
			});
		
	});

	// //加载顾问信息
	// $.ajax({
	// 	type: "get",
	// 	url: 'http://106.75.143.27/counselors?sort=createdTime,desc',
	// 	data: {"page":0},
	// 	contentType: 'application/x-www-form-urlencoded',
	// 	success: requestCounselorsS,
	// 	error: requestCounselorsE
	// });

	$.ajax({
		type: "get",
		url: 'http://106.75.143.27/students',
		// data: {"counselorsId":counselorsId},
		data: {"page":0,"id":localStorage.childId},
		// contentType: 'application/x-www-form-urlencoded',
		success: requestSuccess,
		error: requestError
	});
})